/*
 *  $Id: TextWindow.java 3 2008-11-18 20:02:30Z Nathaniel.Waisbrot $
    Copyright (C) 2008  Nathaniel Waisbrot

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package termint.gui.window;

import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

import termint.gui.SWTTextColor;
import termint.gui.vt.VT320;

/**
 * @author Nathaniel Waisbrot
 *
 */
public class TextWindow extends Window {
	private final SWTTextColor term;
	private final Rectangle screenSize;
	
	public TextWindow(Shell parent, VT320 vt) {
		super(parent.getDisplay());
		screenSize = parent.getDisplay().getClientArea();
		window.setLayout(new FillLayout());
		window.setText("Terminal");
		
		term = new SWTTextColor(window, vt, 16);
		
		// put it in the top right of the screen
		window.setLocation(screenSize.x + screenSize.width - getSize().x, screenSize.y);
	}
	
	@Override
	public void dispose() {
		term.dispose();
		super.dispose();
	}

	/**
	 * The TextWindow's size is fixed, and it is always large enough to contain the VT
	 * @return the window's size
	 */
	public Point getSize() {
		return new Point(term.getSize().x + 50, term.getSize().y + 50);
	}
		
	public Rectangle getBounds() {
		return new Rectangle(getLocation().x, getLocation().y, getSize().x, getSize().y);
	}

	@Override
	public void open() {
		window.setBounds(getBounds());
		super.open();
	}

	@Override
	public void redraw() {
		term.redraw();
	}

	@Override
	public void addKeyListener(KeyListener l) {
		term.addKeyListener(l);		
	}
	
	@Override
	public void addListener(int eventType, Listener l) {
		term.addListener(eventType, l);		
	}
}
